from flask import Blueprint, request, jsonify

api = Blueprint('api', __name__)

@api.route('/calculate', methods=['POST'])
def calculate():
    """
    Calculate endpoint that processes sensor data and returns the sum.
    
    Returns:
        JSON response containing the sum of all values
    """
    try:
        data = request.get_json()
        
        # Extract all float values from the request
        values = [float(value) for value in data.values()]
        
        # Calculate the sum
        result = sum(values)
        
        return jsonify({
            "c": result
        }), 200
        
    except Exception as e:
        return jsonify({
            "error": str(e)
        }), 400 